/*
* 添加领料单明细
* */

import 'dart:async';
import 'dart:convert';
import 'package:center_beijing/api/component_api.dart';
import 'package:center_beijing/api/material_science_api.dart';
import 'package:center_beijing/api/product_api.dart';
import 'package:center_beijing/common/QRScan.dart';
import 'package:center_beijing/common/logutil.dart';
import 'package:center_beijing/common/notification.dart';
import 'package:center_beijing/common/numLengthInputFormatter.dart';
import 'package:center_beijing/common/styles.dart';
import 'package:center_beijing/config/global_config.dart';
import 'package:center_beijing/config/routeConfig.dart';
import 'package:center_beijing/models/selectItem.dart';
import 'package:center_beijing/widgets/custom_input_widget.dart';
import 'package:center_beijing/widgets/custom_loading_widget.dart';
import 'package:center_beijing/widgets/custom_select_widget.dart';
import 'package:center_beijing/widgets/imageSelect_widget.dart';
import 'package:center_beijing/widgets/textarea_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart' as Go;
import 'package:dio/dio.dart' as ImageForm;
import 'package:images_picker/images_picker.dart';
import 'dart:io';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:left_scroll_actions/cupertinoLeftScroll.dart';
import 'package:left_scroll_actions/global/actionListener.dart';

class AddMaterialRequisitionDetail extends StatefulWidget {
  @override
  _AddMaterialRequisitionDetailState createState() =>
      _AddMaterialRequisitionDetailState();
}

class _AddMaterialRequisitionDetailState
    extends State<AddMaterialRequisitionDetail>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;
  CustomLoading loading = CustomLoading.withMessage('提交中...');
  var receive = Go.Get.arguments;
  List<SelectItems> receiptType = []; //需求计划
  SelectItems receipt = SelectItems();
  List<SelectItems> materialType = [
    SelectItems(label: '周转材料', value: '1'),
    SelectItems(label: '非周转材料', value: '2')
  ]; //材料类型
  SelectItems selectMaterialType = SelectItems();
  var currentNum = '0';
  var specification = Map(); //规格型号
  final TextEditingController oddNumbers = TextEditingController(); //单号
  final TextEditingController measure = TextEditingController(); //计量单位
  final TextEditingController number = TextEditingController(); //数量
  final TextEditingController unitPrice = TextEditingController(); //单价
  final TextEditingController priceWithTax = TextEditingController(); //金额(含税)
  final TextEditingController price = TextEditingController(); //金额(不含税)
  final TextEditingController inPrice = TextEditingController(); //入账金额
  final TextEditingController source = TextEditingController(); //市场来源

  List selectList = []; //构件
  String remark = '';
  List<Media> photos = [];
  ImageForm.FormData formData;
  bool listHide = false;

  List<TextEditingController> selectElement = [];

  @override
  void initState() {
    _controller = AnimationController(vsync: this);
    super.initState();
    LogUtil.d(receive);
    this.setState(() {
      oddNumbers.text = receive['docNumber'];
    });
  }

  /*
  * 获取需求计划
  * */
  getAllMaterialRequirement() async {
    var pass = {
      'projectSectionId': GlobalConfig.selectFactory.tag,
      'specId': specification['id'],
    };
    var result = await getMaterialRequirement(pass);
    if (result != null) {
      List<SelectItems> tem = [];
      result.forEach((item) {
        tem.add(SelectItems(label: item['name'], value: item['id'].toString()));
      });
      this.setState(() {
        receiptType = tem;
      });
    }
    LogUtil.d(result);
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  justifyInfo() {
    if (specification['id'] == null) {
      Fluttertoast.showToast(msg: '请选择规格型号');
      return false;
    } else if (selectMaterialType.value == null) {
      Fluttertoast.showToast(msg: '请选择材料类型');
      return false;
    }
    // else if(selectList.length==0){
    //   Fluttertoast.showToast(msg: '请添加构件');
    //   return false;
    // }
    // else if (number.text == '') {
    //   Fluttertoast.showToast(msg: '请输入数量');
    //   return false;
    // } else if (number.text == '0') {
    //   Fluttertoast.showToast(msg: '数量不能为0');
    //   return false;
    // }
    else if (double.parse(currentNum) <
        double.parse(number.text != '' ? number.text : '0')) {
      Fluttertoast.showToast(msg: '领料总数量必须小于库存数量');
      return false;
    }
    return true;
  }

  submit() async {
    var pass = {
      'item': json.encode({
        'id': '',
        'projectSectionId': GlobalConfig.selectFactory.tag,
        'requisitionOrderId': receive['id'],
        'materialSpecId': specification['id'],
        'requestPrice': unitPrice.text,
        'requestQuantity': number.text==''?0:number.text,
        'remark': remark,
        'materialType': selectMaterialType.value,
      }),
      'elements': selectList.length > 0
          ? json.encode(selectList.asMap().keys.map((index) {
              return {
                'elementId': selectList[index]['id'],
                'value': selectElement[index].text != ''
                    ? selectElement[index].text
                    : '1'
              };
            }).toList())
          : json.encode([{'elementId': '', 'value': number.text==''?0:number.text}])
    };
    var result = ((receive
    ['isAcceptItem'] ==
        '1' &&
        receive
        ['recordEditFlag'] !=
            2 &&
        receive
        ['recordEditFlag'] !=
            3 &&
        receive
        ['wfProcInstId'] ==
            null))
        ? await addMaterialRequisitionEntry(pass)
        : await addMaterialRequisitionEntryNo(pass);
    loading.dismiss();
    if (result != null && result['hasError'] == null) {
      Fluttertoast.showToast(msg: '提交成功');
      bus.emit('refreshRequisitionDetailList');
      Go.Get.back();
    }
  }

/*
  * 获取构件详情
  * */
  getCompDetail(compId) async {
    bool have = false;
    for (var i = 0; i < selectList.length; i++) {
      if (selectList[i]['id'] == compId) {
        have = true;
        break;
      }
    }
    if (!have) {
      var result = await getComponentDetail(compId);
      if (result != null) {
        if (result['state'].toString() == '3') {
          Fluttertoast.showToast(msg: '构件已经报废');
        } else if (result['processStatus'] < 3) {
          this.setState(() {
            selectList.add(result);
            selectElement.add(TextEditingController());
          });
        } else {
          Fluttertoast.showToast(msg: '构件已生产完成');
        }
      }
    }
  }

  /*
  * 获取库存数量
  * */
  getMaterialInventory() async {
    var pass = {
      'projectSectionId': GlobalConfig.selectFactory.tag,
      'specId': specification['id'],
      'houseId': receive['outHouseId'],
      'materialType': selectMaterialType.value,
    };
    var result = await statMaterialInventoryBySpecAndHouseId(pass);
    if (result != null) {
      this.setState(() {
        currentNum = result['value'];
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('新增材料明细'),
        ),
        body: Container(
          color: Styles.MainBackgroundColor,
          padding: EdgeInsets.fromLTRB(
              0, 0, 0, MediaQuery.of(context).padding.bottom + 70),
          child: SingleChildScrollView(
            child: Column(
              children: [
                Container(
                  alignment: Alignment.centerLeft,
                  padding: EdgeInsets.fromLTRB(Styles.spacing16,
                      Styles.spacing12, Styles.spacing8, Styles.spacing8),
                  child: Text(
                    '所属单号',
                    style: TextStyle(
                        color: Styles.DetailColor, fontSize: Styles.NormalFont),
                  ),
                ),
                Container(
                  margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                  padding: EdgeInsets.fromLTRB(
                      Styles.spacing8, 0, Styles.spacing8, 0),
                  child: CustomInput(
                    textAlign: TextAlign.left,
                    inputformat: [
                      LengthLimitingTextInputFormatter(10),
                    ],
                    borderWidth: 1,
                    backColor: Styles.GrayLight,
                    title: '',
                    placeHold: '请输入',
                    textInput: this.oddNumbers,
                    clearAll: false,
                    require: false,
                    readOnly: true,
                  ),
                ),
                Container(
                  alignment: Alignment.centerLeft,
                  padding: EdgeInsets.fromLTRB(Styles.spacing16,
                      Styles.spacing12, Styles.spacing8, Styles.spacing8),
                  child: RichText(
                      text: TextSpan(children: [
                    TextSpan(
                      text: "规格型号",
                      style: TextStyle(
                          fontSize: Styles.NormalFont,
                          color: Styles.DetailColor),
                    ),
                    TextSpan(
                      text: '*',
                      style: TextStyle(
                          fontSize: Styles.NormalFont, color: Styles.RedColor),
                    )
                  ])),
                ),
                GestureDetector(
                  behavior: HitTestBehavior.translucent,
                  onTap: () async {
                    var result =
                        await Go.Get.toNamed(RouteConfig.selectSpecifications);
                    if (result != null) {
                      this.setState(() {
                        specification = result;
                        this.measure.text =
                            specification['attr']['measureUnit'];
                        selectMaterialType = SelectItems();
                        currentNum = '0';
                        // receiptType = [];
                        // this.getAllMaterialRequirement();
                      });
                    }
                  },
                  child: Container(
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        border: Border.all(color: Styles.BlueColor, width: 1)),
                    padding: EdgeInsets.fromLTRB(Styles.spacing8,
                        Styles.spacing12, Styles.spacing8, Styles.spacing12),
                    margin: EdgeInsets.fromLTRB(
                        Styles.spacing16, 0, Styles.spacing16, 0),
                    child: Text(
                      this.specification['name'] != null
                          ? this.specification['name']
                          : '选择规格型号',
                      style: TextStyle(
                          color: Styles.BlueColor, fontSize: Styles.NormalFont),
                    ),
                  ),
                ),
                // receiptType.length==0?Container(): Column(
                //    children: [
                //      Container(
                //        alignment: Alignment.centerLeft,
                //        padding: EdgeInsets.fromLTRB(Styles.spacing16,
                //            Styles.spacing12, Styles.spacing8, Styles.spacing8),
                //        child: Text(
                //          '需求计划',
                //          style: TextStyle(
                //              color: Styles.DetailColor, fontSize: Styles.NormalFont),
                //        ),
                //      ),
                //      Container(
                //        color: Colors.white,
                //        margin: EdgeInsets.fromLTRB(
                //            Styles.spacing8, 0, Styles.spacing8, 0),
                //        child: CustomSelectWidget(
                //          require: false,
                //          rightText: receipt.label != null ? receipt.label : '请选择',
                //          titleFont: Styles.NormalFont,
                //          items: receiptType,
                //          selectCallback: (value) => this.setState(() {
                //            receipt = value;
                //          }),
                //          title: '需求计划',
                //        ),
                //      ),
                //    ],
                //  ),
                Container(
                  alignment: Alignment.centerLeft,
                  padding: EdgeInsets.fromLTRB(Styles.spacing16,
                      Styles.spacing12, Styles.spacing8, Styles.spacing8),
                  child: Text(
                    '计量单位',
                    style: TextStyle(
                        color: Styles.DetailColor, fontSize: Styles.NormalFont),
                  ),
                ),
                Container(
                  margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                  padding: EdgeInsets.fromLTRB(
                      Styles.spacing8, 0, Styles.spacing8, 0),
                  child: CustomInput(
                    textAlign: TextAlign.left,
                    inputformat: [
                      LengthLimitingTextInputFormatter(10),
                    ],
                    borderWidth: 1,
                    backColor: Styles.GrayLight,
                    title: '',
                    placeHold: '选择规格型号后自动获取',
                    textInput: this.measure,
                    clearAll: false,
                    require: false,
                    readOnly: true,
                  ),
                ),
                Container(
                  alignment: Alignment.centerLeft,
                  padding: EdgeInsets.fromLTRB(Styles.spacing16,
                      Styles.spacing12, Styles.spacing8, Styles.spacing8),
                  child: RichText(
                      text: TextSpan(children: [
                    TextSpan(
                      text: "材料类型",
                      style: TextStyle(
                          fontSize: Styles.NormalFont,
                          color: Styles.DetailColor),
                    ),
                    TextSpan(
                      text: '*',
                      style: TextStyle(
                          fontSize: Styles.NormalFont, color: Styles.RedColor),
                    )
                  ])),
                ),
                Container(
                  color: Colors.white,
                  margin: EdgeInsets.fromLTRB(
                      Styles.spacing8, 0, Styles.spacing8, 0),
                  child: CustomSelectWidget(
                    require: false,
                    rightText: selectMaterialType.label != null
                        ? selectMaterialType.label
                        : '请选择',
                    titleFont: Styles.NormalFont,
                    items: materialType,
                    selectCallback: (value) => this.setState(() {
                      selectMaterialType = value;
                      this.getMaterialInventory();
                    }),
                    title: '材料类型',
                  ),
                ),
                Container(
                  alignment: Alignment.centerLeft,
                  padding: EdgeInsets.fromLTRB(Styles.spacing16,
                      Styles.spacing12, Styles.spacing8, Styles.spacing8),
                  child: RichText(
                      text: TextSpan(children: [
                    TextSpan(
                      text: "添加构件",
                      style: TextStyle(
                          fontSize: Styles.NormalFont,
                          color: Styles.DetailColor),
                    ),
                  ])),
                ),
                Container(
                  color: Colors.white,
                  padding: EdgeInsets.fromLTRB(Styles.spacing8, Styles.spacing8,
                      Styles.spacing8, Styles.spacing8),
                  margin: EdgeInsets.fromLTRB(
                      Styles.spacing8, 0, Styles.spacing8, 0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          RichText(
                              text: TextSpan(children: [
                            TextSpan(
                                text: '已选构件（',
                                style: TextStyle(
                                    color: Styles.DetailColor,
                                    fontSize: Styles.NormalFont)),
                            TextSpan(
                                text: selectList.length.toString(),
                                style: TextStyle(
                                    color: Styles.BlueColor,
                                    fontSize: Styles.NormalFont)),
                            TextSpan(
                                text: '）',
                                style: TextStyle(
                                    color: Styles.DetailColor,
                                    fontSize: Styles.NormalFont)),
                          ])),
                          GestureDetector(
                            onTap: () {
                              print('点击');
                              this.setState(() {
                                listHide = !listHide;
                              });
                            },
                            child: Container(
                              padding:
                                  EdgeInsets.fromLTRB(Styles.spacing4, 0, 0, 0),
                              child: Text(
                                '查看',
                                style: TextStyle(
                                    color: Styles.BlueColor,
                                    fontSize: Styles.NormalFont),
                              ),
                            ),
                          )
                        ],
                      ),
                      Expanded(
                        child: Container(
                          padding: EdgeInsets.fromLTRB(
                              Styles.spacing16, 0, Styles.spacing16, 0),
                          margin: EdgeInsets.fromLTRB(
                              0, Styles.spacing8, 0, Styles.spacing8),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                child: GestureDetector(
                                  onTap: () async {
                                    var result = await Get.toNamed(
                                        RouteConfig.selectComponent,
                                        arguments: {
                                          'selectList': selectList,
                                          'type': '1,2'
                                        });
                                    if (result != null) {
                                      this.setState(() {
                                        selectList = result;
                                        for (var i = 0;
                                            i < result.length;
                                            i++) {
                                          selectElement
                                              .add(TextEditingController());
                                        }
                                      });
                                    }
                                  },
                                  child: Container(
                                    alignment: Alignment.center,
                                    padding: EdgeInsets.fromLTRB(
                                        Styles.spacing16,
                                        Styles.spacing8,
                                        Styles.spacing16,
                                        Styles.spacing8),
                                    decoration: BoxDecoration(
                                        color: Styles.GrayLight,
                                        border: Border.all(
                                            color: Styles.LineColor, width: 1),
                                        borderRadius: BorderRadius.all(
                                            Radius.circular(4.0.r))),
                                    child: Text(
                                      '搜索构件',
                                      style: TextStyle(
                                          color: Styles.LeftTitleColor,
                                          fontSize: Styles.NormalFont),
                                    ),
                                  ),
                                ),
                              ),
                              GestureDetector(
                                onTap: () async {
                                  var result = await QrScan.scan(context);
                                  if (result != null) {
                                    if (result['type'] == 1) {
                                      this.getCompDetail(result['code']);
                                    } else {
                                      showDialog(
                                          barrierDismissible: false,
                                          context: context,
                                          builder: (BuildContext context) {
                                            return AlertDialog(
                                              title: Text('注意'),
                                              content: Text('请扫描构件二维码！'),
                                              actions: <Widget>[
                                                new Container(
                                                  child: FlatButton(
                                                    child: new Text(
                                                      "确定",
                                                      style: TextStyle(
                                                          color: Colors.red),
                                                    ),
                                                    onPressed: () {
                                                      Navigator.pop(context);
                                                    },
                                                  ),
                                                ),
                                              ],
                                            );
                                          });
                                    }
                                  }
                                },
                                child: Container(
                                  color: Styles.BlueColor,
                                  padding: EdgeInsets.fromLTRB(
                                      Styles.spacing8,
                                      Styles.spacing8,
                                      Styles.spacing8,
                                      Styles.spacing8),
                                  margin:
                                      EdgeInsets.only(left: Styles.spacing16),
                                  child: Image.asset(
                                    'assets/images/scan.png',
                                    width: 20.w,
                                    height: 20.h,
                                    fit: BoxFit.contain,
                                    color: Colors.white,
                                  ),
                                ),
                              )
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                !listHide
                    ? Column(
                        children: this.selectList.asMap().keys.map((index) {
                          return CupertinoLeftScroll(
                            // important, each Row must have different key.
                            // DO NOT use '$index' as Key! Use id or title.
                            key: Key(this.selectList[index].toString()),
                            // left scroll widget will auto close while the other widget is opened and has same closeTag.
                            // 当另一个有相同closeTag的组件打开时，其他有着相同closeTag的组件会自动关闭.
                            closeTag: LeftScrollCloseTag(
                                this.selectList[index].toString()),
                            buttonWidth: 80,
                            child: Container(
                              color: Colors.white,
                              padding: EdgeInsets.fromLTRB(
                                  Styles.spacing8,
                                  Styles.spacing8,
                                  Styles.spacing8,
                                  Styles.spacing8),
                              margin: EdgeInsets.only(top: Styles.spacing8),
                              child: Row(
                                children: [
                                  Expanded(
                                      flex: 2,
                                      child: Column(
                                        crossAxisAlignment:
                                            CrossAxisAlignment.start,
                                        children: [
                                          Row(
                                            children: [
                                              Container(
                                                margin: EdgeInsets.only(
                                                    right: Styles.spacing8),
                                                height: 20.h,
                                                width: 4.w,
                                                color: Styles.BlueColor,
                                              ),
                                              Expanded(
                                                  child: Text(
                                                (this.selectList[index]
                                                                ['compKind'] !=
                                                            null &&
                                                        this.selectList[index]
                                                                    ['compKind']
                                                                [
                                                                'compKindName'] !=
                                                            null)
                                                    ? this.selectList[index]
                                                            ['compKind']
                                                        ['compKindName']
                                                    : '--',
                                                style: TextStyle(
                                                    color: Styles.DetailColor,
                                                    fontSize:
                                                        Styles.Middle16Font),
                                              )),
                                            ],
                                          ),
                                          Container(
                                            margin: EdgeInsets.fromLTRB(
                                                Styles.spacing8,
                                                0,
                                                Styles.spacing8,
                                                0),
                                            child: Column(
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.start,
                                              children: [
                                                Text(
                                                  this.selectList[index]
                                                              ['code'] !=
                                                          null
                                                      ? this.selectList[index]
                                                          ['code']
                                                      : '--',
                                                  style: TextStyle(
                                                      color: Styles.DetailColor,
                                                      fontSize:
                                                          Styles.Middle16Font),
                                                ),
                                                Text(
                                                  (this.selectList[index][
                                                                  'orderInfo'] !=
                                                              null &&
                                                          this.selectList[index]
                                                                      [
                                                                      'orderInfo']
                                                                  [
                                                                  'orderName'] !=
                                                              null)
                                                      ? this.selectList[index]
                                                              ['orderInfo']
                                                          ['orderName']
                                                      : '--',
                                                  style: TextStyle(
                                                      color:
                                                          Styles.LeftTitleColor,
                                                      fontSize:
                                                          Styles.NormalFont),
                                                ),
                                                Text(
                                                  this.selectList[index]
                                                              ['levelPath'] !=
                                                          null
                                                      ? (this
                                                              .selectList[index]
                                                                  ['levelPath']
                                                              .split('&_&_&'))
                                                          .join('-')
                                                      : '--',
                                                  style: TextStyle(
                                                      color:
                                                          Styles.LeftTitleColor,
                                                      fontSize:
                                                          Styles.NormalFont),
                                                ),
                                              ],
                                            ),
                                          )
                                        ],
                                      )),
                                  Container(
                                    width: 120.w,
                                    child: CustomInput(
                                      textFont: Styles.NormalFont,
                                      textAlign: TextAlign.center,
                                      textInput: selectElement[index],
                                      keyboardType:
                                          TextInputType.numberWithOptions(
                                              decimal: true),
                                      borderWidth: 1,
                                      inputformat: [
                                        LengthLimitingTextInputFormatter(10),
                                        NumLengthInputFormatter(digit: 2),
                                      ],
                                      title: '数量',
                                      placeHold: '请输入',
                                      clearAll: false,
                                      require: false,
                                      textChange: (value) {
                                        int bbq = 0;
                                        // if(value!=null&&value!=''){
                                        //   // this.selectElement[index]['currentNumber'] = value;
                                        //   this.selectElement.forEach((element) {
                                        //     bbq = element['currentNumber']!=null?(int.parse(element['currentNumber'])+bbq):bbq;
                                        //   });
                                        // }
                                      },
                                      focusChange: () {
                                        double bbq = 0;
                                        this.selectElement.forEach((element) {
                                          if (element.text != null &&
                                              element.text != '') {
                                            bbq = double.parse(element.text) +
                                                bbq;
                                          }
                                        });
                                        this.number.text = bbq.toString();
                                        if (this.unitPrice.text != '') {
                                          this.inPrice.text = (double.parse(
                                                      this.unitPrice.text) *
                                                  double.parse(
                                                      this.number.text))
                                              .toString();
                                        } else {
                                          this.inPrice.text = '';
                                        }
                                      },
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            buttons: <Widget>[
                              GestureDetector(
                                onTap: () {
                                  this.setState(() {
                                    selectList.remove(this.selectList[index]);
                                    selectElement.removeAt(index);
                                    double bbq = 0;
                                    this.selectElement.forEach((element) {
                                      if (element.text != null &&
                                          element.text != '') {
                                        bbq = double.parse(element.text) + bbq;
                                      }
                                    });
                                    this.number.text = bbq.toString();
                                    if (this.unitPrice.text != '') {
                                      this.inPrice.text = (double.parse(
                                                  this.unitPrice.text) *
                                              double.parse(this.number.text))
                                          .toStringAsFixed(2);
                                    } else {
                                      this.inPrice.text = '';
                                    }
                                  });

                                  print('删除');
                                },
                                child: Container(
                                  margin: EdgeInsets.fromLTRB(
                                      0, 0, Styles.spacing16, 0),
                                  decoration: BoxDecoration(
                                    color: Styles.RedColor,
                                    borderRadius: BorderRadius.all(
                                        Radius.circular(14.0.r)),
                                  ),
                                  alignment: Alignment.center,
                                  child: Column(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      Image(
                                        image: AssetImage(
                                            'assets/images/delete.png'),
                                        width: 16.w,
                                        height: 16.w,
                                        fit: BoxFit.contain,
                                      ),
                                      Text(
                                        '删除',
                                        style: TextStyle(
                                            color: Colors.white,
                                            fontSize: Styles.NormalFont),
                                      )
                                    ],
                                  ),
                                ),
                              ),
                            ],
                            onTap: () {
                              print('tap row');
                            },
                          );
                        }).toList(),
                      )
                    : Container(),
                Container(
                  alignment: Alignment.centerLeft,
                  padding: EdgeInsets.fromLTRB(Styles.spacing16,
                      Styles.spacing12, Styles.spacing8, Styles.spacing8),
                  child: RichText(
                      text: TextSpan(children: [
                    TextSpan(
                      text: "总数量(${this.currentNum.toString()})",
                      style: TextStyle(
                          fontSize: Styles.NormalFont,
                          color: Styles.DetailColor),
                    ),
                  ])),
                ),
                Container(
                  margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                  padding: EdgeInsets.fromLTRB(
                      Styles.spacing8, 0, Styles.spacing8, 0),
                  child: CustomInput(
                    backColor: Styles.GrayLight,
                    textAlign: TextAlign.left,
                    borderWidth: 1,
                    inputformat: [],
                    title: '',
                    placeHold: '结果自动累计',
                    textInput: this.number,
                    clearAll: false,
                    require: false,
                  ),
                ),
                Container(
                  alignment: Alignment.centerLeft,
                  padding: EdgeInsets.fromLTRB(Styles.spacing16,
                      Styles.spacing12, Styles.spacing8, Styles.spacing8),
                  child: Text(
                    '领用单价(元)',
                    style: TextStyle(
                        color: Styles.DetailColor, fontSize: Styles.NormalFont),
                  ),
                ),
                Container(
                  margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                  padding: EdgeInsets.fromLTRB(
                      Styles.spacing8, 0, Styles.spacing8, 0),
                  child: CustomInput(
                    textAlign: TextAlign.left,
                    keyboardType:
                        TextInputType.numberWithOptions(decimal: true),
                    borderWidth: 1,
                    inputformat: [
                      LengthLimitingTextInputFormatter(10),
                      NumLengthInputFormatter(digit: 2)
                    ],
                    title: '',
                    placeHold: '请输入',
                    textInput: this.unitPrice,
                    clearAll: false,
                    require: false,
                    focusChange: () {
                      if (this.unitPrice.text != '') {
                        this.inPrice.text = (double.parse(this.unitPrice.text) *
                                double.parse(this.number.text))
                            .toStringAsFixed(2);
                      } else {
                        this.inPrice.text = '';
                      }
                    },
                  ),
                ),
                Container(
                  alignment: Alignment.centerLeft,
                  padding: EdgeInsets.fromLTRB(Styles.spacing16,
                      Styles.spacing12, Styles.spacing8, Styles.spacing8),
                  child: Text(
                    '金额(元)',
                    style: TextStyle(
                        color: Styles.DetailColor, fontSize: Styles.NormalFont),
                  ),
                ),
                Container(
                  margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                  padding: EdgeInsets.fromLTRB(
                      Styles.spacing8, 0, Styles.spacing8, 0),
                  child: CustomInput(
                    textAlign: TextAlign.left,
                    keyboardType:
                        TextInputType.numberWithOptions(decimal: true),
                    borderWidth: 1,
                    backColor: Styles.GrayLight,
                    inputformat: [
                      LengthLimitingTextInputFormatter(20),
                      NumLengthInputFormatter(digit: 2)
                    ],
                    title: '',
                    placeHold: '自动计算结果',
                    textInput: this.inPrice,
                    clearAll: false,
                    require: false,
                    readOnly: true,
                  ),
                ),

                Container(
                  color: Colors.white,
                  margin: EdgeInsets.fromLTRB(
                      Styles.spacing8, Styles.spacing8, Styles.spacing8, 0),
                  padding: EdgeInsets.fromLTRB(
                      Styles.spacing8, 0, Styles.spacing8, 0),
                  child: TextAreaWidget(
                    labelText: '备注',
                    defaultValue: '',
                    placeholder: '请输入备注',
                    disabled: false,
                    required: false,
                    rows: 4,
                    onChange: (value) => this.setState(() {
                      remark = value;
                    }),
                  ),
                ),
              ],
            ),
          ),
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        floatingActionButton: Container(
          color: Colors.white,
          padding: EdgeInsets.fromLTRB(
              Styles.spacing8, Styles.spacing8, Styles.spacing8, 10),
          child: Container(
            decoration: new BoxDecoration(
              border: Border.all(width: 1, color: Styles.BlueColor),
              //背景
              color: Styles.LightBlueColor,
              //设置四周圆角 角度
              borderRadius: BorderRadius.all(Radius.circular(12.0)),
            ),
            margin: EdgeInsets.fromLTRB(Styles.spacing8, 0, Styles.spacing8, 0),
            child: FlatButton(
                onPressed: () {
                  FocusScope.of(context).requestFocus(new FocusNode());
                  const timeout = const Duration(milliseconds: 200); // 当前时间
                  Timer(timeout, () {
                    //callback function
                    if (justifyInfo()) {
                      showDialog(
                          barrierDismissible: false,
                          context: this.context,
                          builder: (BuildContext context) {
                            return AlertDialog(
                              title: Text('注意'),
                              content: Text('确认完成吗？'),
                              actions: <Widget>[
                                new Container(
                                  child: FlatButton(
                                    child: new Text(
                                      "取消",
                                      style: TextStyle(color: Colors.black),
                                    ),
                                    onPressed: () {
                                      Navigator.pop(context);
                                    },
                                  ),
                                ),
                                new Container(
                                  child: FlatButton(
                                    child: new Text(
                                      "确定",
                                      style: TextStyle(color: Colors.red),
                                    ),
                                    onPressed: () {
                                      Navigator.pop(context);
                                      this.submit();
                                    },
                                  ),
                                ),
                              ],
                            );
                          });
                    }
                  });
                },
                child: Container(
                  height: Styles.MainButtonHeight,
                  alignment: Alignment.center,
                  child: Text('完成',
                      style: TextStyle(
                          color: Styles.BlueColor,
                          fontSize: Styles.MainButtonTextFont)),
                )),
          ),
        ));
  }
}
